#ifndef __HIKARI_CreateTrimeshCollider___FILE__DEFINED
#define __HIKARI_CreateTrimeshCollider___FILE__DEFINED

#include "hikari.h"

class CreateTrimeshCollider:public BaseHikariScript{
public:
//PLEASE DO NOT MODIFY THIS SECTION
//PROPERTIES_SECTION_START
//PROPERTIES_SECTION_END
	
	virtual void sceneLoaded(HObj*object, HikariContext*context){
		ITriangleSelector*selector;
		ISceneManager*sm=context->getSceneManager();
		IMeshSceneNode*node=dynamic_cast<IMeshSceneNode*>(object->getInternalNode());
		if(node!=NULL){
			selector=sm->createTriangleSelector(node->getMesh(), node);
			object->getInternalNode()->setTriangleSelector(selector);
		}else{
			IAnimatedMeshSceneNode*animnode=dynamic_cast<IAnimatedMeshSceneNode*>(object->getInternalNode());
			if(animnode!=NULL){
				selector=sm->createTriangleSelector(animnode->getMesh(), animnode);
				object->getInternalNode()->setTriangleSelector(selector);
			}else{
				Utils::errorLog(L"cannot create triangle selector");
			}
		}

		IMetaTriangleSelector*metaSelector=(IMetaTriangleSelector*)context->getProperty(L"metaSelector");
		if(metaSelector==NULL){
			metaSelector=sm->createMetaTriangleSelector();
			context->setProperty(L"metaSelector", metaSelector);
		}

		metaSelector->addTriangleSelector(selector);
		selector->drop();
	}

	virtual void update(HObj*object, HikariContext*context){
	
	}

	IMPLEMENT_RTTI(CreateTrimeshCollider, BaseHikariScript);
};
BEGIN_REFLECTION_METADATA(CreateTrimeshCollider, base_rtti_object)
END_REFLECTION_METADATA(CreateTrimeshCollider)
#endif